package com.example.g7640.mapper;

import com.example.g7640.dto.ProductDto;
import com.example.g7640.entity.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author  
 * @since 2024-03-18
 */
public interface ProductMapper extends BaseMapper<Product> {



    @Update("update product set inventory = inventory - #{quantity} where id=#{id} and inventory >= #{quantity}")
    int reduceInventory(@Param("id") Integer id,@Param("quantity") Integer quantity);


    @Update("update product set inventory = inventory + #{quantity} where id=#{id}")
    int addInventory(@Param("id") Integer id,@Param("quantity") Integer quantity);

}
